<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ include file="../../../common/common-easyui.jspf" %>
<!DOCTYPE html >
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>考试安排维护</title>
</head>
<body>
<table id="dg" title="考试安排维护" class="easyui-datagrid" style="width:100%;height:100%"
       data-options="
			url:'arrangeInfoController?flag=list',
			toolbar:'#toolbar',
			rownumbers:'true',
			 fitColumns:'true' ,
			 singleSelect:'true'">
    <thead>
    <tr>
        <th data-options="field:'arrangeId'" width="50">考试安排编号</th>
        <th data-options="field:'paperId'" width="50">试卷编号</th>
        <th data-options="field:'classId'" width="50">班级</th>
        <th data-options="field:'teaId'" width="50">老师编号</th>
        <th data-options="field:'leader'" width="50">负责人编号</th>
        <th data-options="field:'startTime',
					formatter:function(value) {
						return getTimer(value);
					 }
				" width="50">开始时间
        </th>
        <th data-options="field:'endTime',
					formatter:function(value) {
						return getTimer(value);
					 }
				" width="50">结束时间
        </th>
        <th data-options="field:'address'" width="50">考试地址</th>
        <th data-options="field:'courseId'" width="50">科目编号</th>
    </tr>
    </thead>
</table>
<div id="toolbar">
    <a href="#" class="easyui-linkbutton" data-options=" iconCls:'icon-edit', plain:'true'" onclick="editArrange()">编辑考试安排</a>
    <a href="#" class="easyui-linkbutton" data-options=" iconCls:'icon-remove', plain:'true'"
       onclick="destroyArrange()">移除考试安排</a>
</div>
<div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
     data-options="closed:'true', buttons:'#dlg-buttons'">
    <div class="ftitle">试卷信息</div>
    <form id="fm" method="post">
        <div class="fitem">
            <label>考试安排编号:</label>
            <input name="arrangeId">
        </div>
        <div class="fitem">
            <label>试卷编号:</label>
            <input name="paperId">
        </div>
        <div class="fitem">
            <label>班级:</label>
            <input name="classId">
        </div>
        <div class="fitem">
            <label>老师编号:</label>
            <input name="teaId">
        </div>

        <div class="fitem">
            <label>负责人编号:</label>
            <input name="leader">
        </div>
        <div class="fitem">
            <label>开始时间:</label>
            <input type="datetime-local" name="startTime">
        </div>
        <div class="fitem">
            <label>结束时间:</label>
            <input type="datetime-local" name="endTime">
        </div>
        <div class="fitem">
            <label>考试地址:</label>
            <input name="address">
        </div>
        <div class="fitem">
            <label>科目编号:</label>
            <input name="courseId">
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="#" class="easyui-linkbutton" data-options=" iconCls:'icon-ok'" onclick="saveArrange()">Save</a>
    <a href="#" class="easyui-linkbutton" data-options=" iconCls:'icon-cancel'"
       onclick="javascript:$('#dlg').dialog('close')">Cancel</a>
</div>
<script type="text/javascript">

    //修改函数
    function editArrange() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $('#dlg').dialog('open').dialog('setTitle', '修改组卷规则');
            $('#fm').form('load', row);
            url = 'arrangeInfoController?flag=update&arrangeId=' + row.arrangeId;
        }
    }
    //保存函数
    function saveArrange() {
        $('#fm').form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (data) {

                if (data == "ok") {
                    $('#dlg').dialog('close');		// 清除数据
                    $('#dg').datagrid('reload');	// 重新加载数据
                } else {
                    $.messager.show({
                        title: 'Error',
                        msg: result.errorMsg
                    });
                }
            }
        });
    }
    //删除函数
    function destroyArrange() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('Confirm', '确定删除吗?', function (r) {
                if (r) {
                    $.get('arrangeInfoController', {flag: "dele", arrangeId: row.arrangeId}, function (data) {
                        if (data == "ok") {
                            $('#dg').datagrid('reload');	// 重新加载数据
                        } else {
                            $.messager.show({	//错误提示
                                title: 'Error',
                                msg: result.errorMsg
                            });
                        }
                    });
                }
            });
        }
    }
    // 时间处理
    function getTimer(value) {
        // 创建一个日期对象
        // new 把该对象放到内存空间中存储起来
        var date = new Date(value);
        // 获取年份
        var year = date.getFullYear();
        // 获取月份
        var month = date.getMonth() + 1;
        // 获取天数
        var day = date.getDate();

        // 获取小时
        var hours = handler(date.getHours());
        // 获取分钟数
        var minutes = handler(date.getMinutes());
        // 获取秒数
        var seconds = handler(date.getSeconds());

        var currentTime = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;

        return currentTime;
    }

    /*定义处理如果时间小于10前面加0的函数*/
    function handler(time) {

        if (time < 10) {
            time = "0" + time;
        }

        // 返回当前格式化后的字符串
        return time;

    }

</script>
</body>
</html>